<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false" %>
  <script type="text/javascript">


      $(function(){
          $("#dailyProductdatagrid").datagrid({
              url:'${pageContext.request.contextPath}/product/showAll?type=日租礼服',
              pagination:true,
              method:'get',
              fit:true,
              pageSize:5,
              pageList:[5,10,15,20,25],
              fitColumns:true,
              striped:true,
              remoteSort:false,
              checkOnSelect:false,
              toolbar:'#dailyProducttoolbar',
              onLoadSuccess:function(){
                  $(".btn").linkbutton({
                      plain:true
                  })
              },
              columns:[[
                  {field:'cks',checkbox:true},
                  {title:'商品编号',field:'id',align:'center',width:200},
                  {title:'名称',field:'name',align:'center',width:100},
                  {title:'市场价',field:'marketvalue',align:'center',width:100},
                  {title:'押金',field:'deposit',align:'center',width:100},
                  {title:'简介',field:'content',align:'center',width:100},
                  {title:'材质',field:'material',align:'material',width:100},
                  {title:'状态',field:'status',align:'center',width:150},
                  {title:'操作',field:'options',width:300,formatter:function(index,row,value){
                          return "<a href='javascript:;' onclick=\"deleteProduct('"+row.id+"')\"  class='btn' data-options=\"iconCls:'icon-remove'\">删除</a>&nbsp;&nbsp;" +
                              "<a href='javascript:;' onclick=\"openDailyUpdate('"+row.id+"')\" class='btn' data-options=\"iconCls:'icon-edit'\"&nbsp;&nbsp;>更新</a>"+
                              "<a href='javascript:;' onclick=\"openUpdateImageDialog('"+row.id+"')\" class='btn' data-options=\"iconCls:'icon-edit'\">更新图片</a>&nbsp;&nbsp;"+
                              "<a href='javascript:;' onclick=\"openSize('"+row.id+"')\" class='btn' data-options=\"iconCls:'icon-edit'\">更新尺寸</a>"


                      }}
              ]]
          })

      });
      //删除商品
      function deleteProduct(id){
          $.messager.confirm('删除提示','确定要删除吗?',function(r){
              if(r){
                  $.post("${pageContext.request.contextPath}/product/delete",{"id":id},function(result){
                      showMessage("删除提示",result.message);
                      $("#dailyProductdatagrid").datagrid('reload');
                  })
              }
          })
      }

      //批量删除
      function deleteSome(){
          var rows=$("#dailyProductdatagrid").datagrid("getSelections");
          if(rows.length>0){
              $.messager.confirm('删除提示','确定要删除吗?',function(r){
                  if(r){
                      var ids=[];
                      $.each(rows,function(index,row){
                          ids.push(row.id);
                      });
                      $.ajax({
                          url:"${pageContext.request.contextPath}/product/deleteSome",
                          data:{ids:ids},
                          dataType:"JSON",
                          method:'post',
                          traditional:true,
                          success:function(result){
                              showMessage("批量删除提示",result.message);
                              $("#dailyProductdatagrid").datagrid('reload');
                          }
                      })
                  }
              })
          }else{
              $.messager.alert("批量删除提示","请至少选择一项!");
          }
      }

      //打开添加商品面板
      function openaddDailyProduct(){

          $("#addDailyProductDialog").dialog({
              title:'添加商品信息',
              width:500,
              height:550,
              iconCls:'icon-man',
              href:'${pageContext.request.contextPath}/back/product/addDailyProduct.jsp',
              buttons:[{
                  text:'添加',
                  iconCls:'icon-add',
                  handler:addDailyProduct
              },{
                  text:'关闭',
                  iconCls:'icon-cancel',
                  handler:function(){
                      $("#addDailyProductDialog").dialog('close');
                  }
              }]
          })
      }

      //添加商品
      function addDailyProduct(){
          $("#addDailyProductForm").form('submit',{
              url:'${pageContext.request.contextPath}/product/save',
              onSubmit:function(){
                  return $("#addDailyProductForm").form('validate');
              },
              success:function(res){
                  var result = $.parseJSON(res);;
                  showMessage("添加信息",result.message);
                  $("#addDailyProductDialog").dialog('close');
                  $("#dailyProductdatagrid").datagrid('reload')
              }
          });
      }
      //打开更新窗口
      function openDailyUpdate(id){
          $("#updateDailyProductDialog").dialog({
              href:'${pageContext.request.contextPath}/back/product/updateDailyProduct.jsp?id='+id,
              width:600,
              height:600,
              title:'更新商品信息',
              iconCls:'icon-man',
              buttons:[{
                  text:'更新',
                  handler:updateDailyProduct,
                  iconCls:'icon-save'
              },{
                  text:'关闭',
                  handler:function(){
                      $("#updateDailyProductDialog").dialog('close');
                  },
                  iconCls:'icon-cancel'
              }],onLoad:function(){
                  $("#updateDailyProductForm").form('load','${pageContext.request.contextPath}/product/findById?id='+id);
              }
          });
      }

      //更新商品信息
      function updateDailyProduct(){
          $("#updateDailyProductForm").form({
              url:'${pageContext.request.contextPath}/product/update',
              onSubmit:function(){
                  return $(this).form('validate');
              },
              success:function(res){
                  var result = $.parseJSON(res);
                 showMessage("更新提示信息",result.message);
                  $("#updateDailyProductDialog").dialog('close');
                  $("#dailyProductdatagrid").datagrid('reload');
              },
          });
          $("#updateDailyProductForm").form('submit');
      }
      //打开更新图片窗口
      function openUpdateImageDialog(id){
          $("#updateDailyImageDialog").dialog({
              href:'${pageContext.request.contextPath}/back/product/updateImage.jsp?id='+id,
              width:1200,
              height:600,
              title:'更新商品图片信息',
              iconCls:'icon-man',
              buttons:[{
                  text:'关闭',
                  handler:function(){
                      $("#updateImageDialog").dialog('close');
                  },
                  iconCls:'icon-cancel'
              }]
          });
      }
      function showMessage(title,message){
          $.messager.show({
              title:title,
              msg:message,
              timeout:5000,
              showType:'slide'
          });
      }
      
      function openSize(id) {
          $("#updateDailySize").dialog({
              href:'${pageContext.request.contextPath}/back/product/updateDailySize.jsp?id='+id,
              width:1200,
              height:600,
              title:'更新商品图片信息',
              iconCls:'icon-man',
              buttons:[{
                  text:'关闭',
                  handler:function(){
                      $("#updateDailySize").dialog('close');
                  },
                  iconCls:'icon-cancel'
              }]
          })
      }
  </script>
</head>




<table id="dailyProductdatagrid" ></table>
<div id="dailyProducttoolbar">
  <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="openaddDailyProduct();">添加日租商品</a>
  <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="deleteSome();">删除选中</a>
</div>

<div id="addDailyProductDialog"></div>
<div id="updateDailyProductDialog"></div>
<div id="updateDailyImageDialog"></div>
<div id="updateDailySize"></div>

</form>

